package com.study.base

import android.app.Application
import com.blankj.utilcode.util.CrashUtils
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.Utils
import com.facebook.stetho.Stetho
import java.io.File

/**
 * <pre>
 *     author : fauks
 *     time   : 2020/03/21
 *     desc   :
 * </pre>
 */
abstract class BaseApp : Application() {

    companion object {
        lateinit var application: Application
    }

    override fun onCreate() {
        super.onCreate()
        application = this
        initAndroidUtils()
        initTest()
    }

    private fun initTest() {
        Stetho.initializeWithDefaults(this)
    }

    private fun initAndroidUtils() {
        Utils.init(this)
        LogUtils.getConfig().setGlobalTag("fauks")
                .setLogHeadSwitch(true)
                .setBorderSwitch(true)
        val file = File(application.externalCacheDir, "crash")
        CrashUtils.init(file) {
            LogUtils.e("faukscrash:$it")
        }
    }

    /**
     * Application初始化
     */
    abstract fun initModuleApp(application: Application)

    /**
     * Application初始化完毕执行的操作
     */
    abstract fun initModuleData(application: Application)
}